package com.centling.smartSealForPhone.activity

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentPagerAdapter
import android.support.v4.view.ViewPager
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import com.centling.smartSealForPhone.R
import com.centling.smartSealForPhone.fragment.BaseFragment
import kotlinx.android.synthetic.main.activity_feature_demo_display.*
import kotlinx.android.synthetic.main.fragment_feature_display.view.*

/**
 * show the function
 * 根据不同身份进行功能展示
 */

class FeatureDemoDisplayActivity : BaseActivity() {

    private var res_0:IntArray?=null
    private var tips_0 :Array<String>?=null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_feature_demo_display)

        window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)

        setData(intent.getStringExtra("feature_type"))

        fl_feature_demo_quit.setOnClickListener {
            finish()
        }

        val usedRes = res_0!!
        val usedTips = tips_0!!

        vp_feature_demo.adapter = object : FragmentPagerAdapter(supportFragmentManager){
            override fun getItem(position: Int): Fragment {
                val fragment = DisplayFragment.getInstance(usedRes,usedTips, position)
                fragment.viewPager = vp_feature_demo
                return fragment
            }

            override fun getCount(): Int = usedRes.size
        }

        vp_feature_demo.addOnPageChangeListener(object:ViewPager.OnPageChangeListener{
            override fun onPageScrollStateChanged(state: Int) {

            }

            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {

            }

            override fun onPageSelected(position: Int) {
//                功能演示，页面信息展示
                tv_feature_demo_next.text = "${position + 1}/${usedTips.size}\n${usedTips[position]}"
                if(position == 0){
                    iv_feature_demo_back.visibility = View.GONE
                }else{
                    iv_feature_demo_back.visibility = View.VISIBLE
                }
                if(position == usedTips.size - 1){
                    iv_feature_demo_next.visibility = View.GONE
                }else{
                    iv_feature_demo_next.visibility = View.VISIBLE
                }
            }
        })

        iv_feature_demo_back.visibility = View.GONE
        tv_feature_demo_next.text = "${1}/${usedTips.size}\n${usedTips[0]}"

        fl_feature_demo_back.setOnClickListener {
            if(vp_feature_demo.currentItem > 0){
                vp_feature_demo.currentItem = vp_feature_demo.currentItem - 1
            }
        }

        fl_feature_demo_next.setOnClickListener {
            if(vp_feature_demo.currentItem < usedRes.size - 1){
                vp_feature_demo.currentItem = vp_feature_demo.currentItem + 1
            }
        }
    }

    open class DisplayFragment : BaseFragment(){

        lateinit var viewPager:ViewPager

        companion object {
            fun getInstance(res: IntArray, tips:Array<String>, pos: Int): DisplayFragment {
                val fragment = DisplayFragment()
                val args = Bundle()
                args.putIntArray("resource", res)
                args.putStringArray("tips", tips)
                args.putInt("position", pos)
                fragment.arguments = args
                return fragment
            }
        }

        override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
            val view = inflater.inflate(R.layout.fragment_feature_display, container, false)
            val res = arguments!!.getIntArray("resource")
            val pos = arguments!!.getInt("position")
            view.iv_feature_display.setImageResource(res[pos % res.size])
            view.iv_feature_display.setOnClickListener {
                if(viewPager.currentItem < res.size - 1){
                    viewPager.currentItem = viewPager.currentItem + 1
                }
            }
            return view
        }
    }

    /**
     * 根据不同身份进行加载相应数据
     */
    private fun setData(type:String){
        when (type){
            "0_EQUIP_COMMON_USER_0" ->{
                res_0= intArrayOf(R.drawable.function_common_1,R.drawable.function_common_2,R.drawable.function_common_3,R.drawable.function_common_4,R.drawable.function_common_5,
                        R.drawable.function_common_6,R.drawable.function_common_7,R.drawable.function_common_8,R.drawable.function_common_9,R.drawable.function_common_10)
                tips_0= arrayOf("点击进入用印申请", "选择限次或限时申请", "填写相应信息并提交申请",
                        "点击进入用印列表", "点击'用印'进入用印界面", "点击用印按钮开始用印",
                        "用完后点击'退出'按钮", "点击加号添加图片", "点击'上传图片'按钮完成用印",
                        "点击'历史记录'可查看记录")
            }
//            "0_EQUIP_COMMON_USER_1" ->{}
//            "0_EQUIP_COMMON_USER_2" ->{}
            "0_EQUIP_ADMIN_0" ->{
                res_0= intArrayOf(R.drawable.function_taishi_seal1,R.drawable.function_taishi_seal2,R.drawable.function_taishi_seal3,R.drawable.function_taishi_seal4,R.drawable.function_taishi_seal5,
                        R.drawable.function_taishi_seal6,R.drawable.function_taishi_seal7,R.drawable.function_taishi_seal8,R.drawable.function_taishi_seal9,R.drawable.function_taishi_seal10)
                tips_0= arrayOf("点击进入用印申请", "选择限次或限时申请", "填写相应信息并提交申请",
                        "点击进入用印列表", "点击'用印'进入用印界面", "点击用印按钮开始用印",
                        "用完后点击'退出'按钮", "点击加号添加图片", "点击'上传图片'按钮完成用印",
                        "点击'历史记录'可查看记录")
            }
//            "0_EQUIP_ADMIN_1" ->{}
//            "0_EQUIP_ADMIN_2" ->{}
            "0_EQUIP_OPERATOR_0" ->{
                res_0= intArrayOf(R.drawable.function_taishi_seal1,R.drawable.function_taishi_seal2,R.drawable.function_taishi_seal3,R.drawable.function_taishi_seal4,R.drawable.function_taishi_seal5,
                        R.drawable.function_taishi_seal6,R.drawable.function_taishi_seal7,R.drawable.function_taishi_seal8,R.drawable.function_taishi_seal9,R.drawable.function_taishi_seal10)
                tips_0= arrayOf("点击进入用印申请", "选择限次或限时申请", "填写相应信息并提交申请",
                        "点击进入用印列表", "点击'用印'进入用印界面", "点击用印按钮开始用印",
                        "用完后点击'退出'按钮", "点击加号添加图片", "点击'上传图片'按钮完成用印",
                        "点击'历史记录'可查看记录")
            }
//            "0_EQUIP_OPERATOR_1" ->{}
//            "0_EQUIP_OPERATOR_2" ->{}
            "0_SERVER_USER_3"->{
                res_0= intArrayOf(R.drawable.function_checker1,R.drawable.function_checker2,R.drawable.function_checker3,R.drawable.function_checker3_1,R.drawable.function_checker9,R.drawable.function_checker10)
                tips_0= arrayOf("点击审批选项","点击查看详细信息或点击‘审批’开始审核","选择审批类型","选择审批类型","点击历史记录可查看记录","点击可查找记录")
            }
            "0_SERVER_USER_4"->{
                res_0= intArrayOf(R.drawable.function_checker4,R.drawable.function_checker5,R.drawable.function_checker6,R.drawable.function_checker7,R.drawable.function_checker8,
                        R.drawable.function_checker9,R.drawable.function_checker10)
                tips_0= arrayOf("点击复审选项","点击查看详细信息或点击‘复审’开始审核","选择复审类型,若选择复审成功,点击确定,则复审成功","若选择复审失败，应选择失败类型",
                        "若选择补拍，选择需要补拍的图片后点击确定","点击历史记录可查看记录","点击可查找记录")
            }

            "1_EQUIP_COMMON_USER_0" ->{
                res_0= intArrayOf(R.drawable.function_common_1,R.drawable.function_common_2,R.drawable.function_common_3,R.drawable.function_common_4,R.drawable.function_common_5,
                        R.drawable.function_common_6,R.drawable.function_common_7,R.drawable.function_common_8,R.drawable.function_common_9,R.drawable.function_common_10)
                tips_0= arrayOf("点击进入用印申请", "选择限次或限时申请", "填写相应信息并提交申请",
                        "点击进入用印列表", "点击'用印'进入用印界面", "点击用印按钮开始用印",
                        "用完后点击'退出'按钮", "点击加号添加图片", "点击'上传图片'按钮完成用印",
                        "点击'历史记录'可查看记录")
            }
//            "1_EQUIP_COMMON_USER_1" ->{}
//            "1_EQUIP_COMMON_USER_2" ->{}
            "1_EQUIP_ADMIN_0" ->{
                res_0= intArrayOf(R.drawable.function_admin_seal1,R.drawable.function_admin_seal2,R.drawable.function_admin_seal3,R.drawable.function_admin_seal4,R.drawable.function_admin_seal5,
                        R.drawable.function_admin_seal6,R.drawable.function_admin_seal7,R.drawable.function_admin_seal8,R.drawable.function_admin_seal9,R.drawable.function_admin_seal10)
                tips_0= arrayOf("点击进入用印申请", "选择限次或限时申请", "填写相应信息并提交申请",
                        "点击进入用印列表", "点击'用印'进入用印界面", "点击用印按钮开始用印",
                        "用完后点击'退出'按钮", "点击加号添加图片", "点击'上传图片'按钮完成用印",
                        "点击'历史记录'可查看记录")
            }
            "1_EQUIP_ADMIN_1" ->{
                res_0= intArrayOf(R.drawable.function_admin_change1,R.drawable.function_admin_change2,R.drawable.function_admin_change3,R.drawable.function_admin_change4,R.drawable.function_admin_change5,
                        R.drawable.function_admin_change6,R.drawable.function_admin_change7)
                tips_0= arrayOf("点击进入换章列表", "点击加号进入换章申请界面", "填写相应信息并提交申请",
                        "点击换章记录可查看详情", "点击'换章'按钮进入换章界面", "点击'继续'按钮",
                        "完成换章后，点击'确定'退出")
            }
            "1_EQUIP_ADMIN_2" ->{
                res_0= intArrayOf(R.drawable.function_admin_boss1,R.drawable.function_admin_boss2,R.drawable.function_admin_boss3,R.drawable.function_admin_boss4,R.drawable.function_admin_boss5,R.drawable.function_admin_boss6)
                tips_0= arrayOf("点击进入解锁模式列表", "点击加号进入解锁模式申请界面", "填写相应信息并提交申请",
                        "点击解锁记录可查看详情", "点击'开启'按钮开启解锁模式", "点击'关闭'按钮结束解锁模式")
            }
            "1_EQUIP_OPERATOR_0" ->{
                res_0= intArrayOf(R.drawable.function_op_seal1,R.drawable.function_op_seal2,R.drawable.function_op_seal3,R.drawable.function_op_seal4,R.drawable.function_op_seal5,
                        R.drawable.function_op_seal6,R.drawable.function_op_seal7,R.drawable.function_op_seal8,R.drawable.function_op_seal9,R.drawable.function_op_seal10)
                tips_0= arrayOf("点击进入用印申请", "选择限次或限时申请", "填写相应信息并提交申请",
                        "点击进入用印列表", "点击'用印'进入用印界面", "点击用印按钮开始用印",
                        "用完后点击'退出'按钮", "点击加号添加图片", "点击'上传图片'按钮完成用印",
                        "点击'历史记录'可查看记录")
            }
            "1_EQUIP_OPERATOR_1" ->{
                res_0= intArrayOf(R.drawable.function_op_change1,R.drawable.function_op_change2,R.drawable.function_op_change3,R.drawable.function_op_change4,R.drawable.function_op_change5,
                        R.drawable.function_op_change6,R.drawable.function_op_change7)
                tips_0= arrayOf("点击进入换章列表", "点击加号进入换章申请界面", "填写相应信息并提交申请",
                        "点击换章记录可查看详情", "点击'换章'按钮进入换章界面", "点击'继续'按钮",
                        "完成换章后，点击'确定'退出")
            }
            "1_EQUIP_OPERATOR_2" ->{
                res_0= intArrayOf(R.drawable.function_op_boss1,R.drawable.function_op_boss2,R.drawable.function_op_boss3,R.drawable.function_op_boss4,R.drawable.function_op_boss5,R.drawable.function_op_boss6)
                tips_0= arrayOf("点击进入解锁模式列表", "点击加号进入解锁模式申请界面", "填写相应信息并提交申请",
                        "点击解锁记录可查看详情", "点击'开启'按钮开启解锁模式", "点击'关闭'按钮结束解锁模式")
            }
            "1_SERVER_USER_3"->{
                res_0= intArrayOf(R.drawable.function_checker1,R.drawable.function_checker2,R.drawable.function_checker3,R.drawable.function_checker3_1,R.drawable.function_checker9,R.drawable.function_checker10)
                tips_0= arrayOf("点击审批选项","点击查看详细信息或点击‘审批’开始审核","选择审批类型","选择审批类型","点击历史记录可查看记录","点击可查找记录")
            }
            "1_SERVER_USER_4"->{
                res_0= intArrayOf(R.drawable.function_checker4,R.drawable.function_checker5,R.drawable.function_checker6,R.drawable.function_checker7,R.drawable.function_checker8,
                        R.drawable.function_checker9,R.drawable.function_checker10)
                tips_0= arrayOf("点击复审选项","点击查看详细信息或点击‘复审’开始审核","选择复审类型,若选择复审成功,点击确定,则复审成功","若选择复审失败，应选择失败类型",
                        "若选择补拍，选择需要补拍的图片后点击确定","点击历史记录可查看记录","点击可查找记录")
            }
        }
    }
}
